// 新建文件并写入以下内容
package com.share.modules.monitor.listener;

import com.alibaba.cloud.nacos.registry.NacosServiceRegistry;
import com.alibaba.cloud.nacos.registry.NacosRegistration;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.web.context.WebServerInitializedEvent;
import org.springframework.cloud.client.serviceregistry.AbstractAutoServiceRegistration;
import org.springframework.context.event.EventListener;
import org.springframework.stereotype.Component;

@Component
public class DelayedNacosRegistrationListener {
    @Autowired
    private NacosServiceRegistry nacosServiceRegistry;

    @Autowired
    private NacosRegistration registration;

    @EventListener(WebServerInitializedEvent.class)
    public void onApplicationEvent(WebServerInitializedEvent event) {
        // 延迟注册到 Nacos
        nacosServiceRegistry.register(registration);
    }
}